package com.hliushi.controller;

import com.hliushi.exception.ExceptionCast;
import com.hliushi.response.CommonCode;
import com.hliushi.response.JsonResult;
import com.hliushi.response.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ExceptionController
 * @Description TODO
 * @Author liushi
 * @Date 2020/9/16 22:34
 * @Version V1.0
 **/
@RestController
@RequestMapping("/exception")
public class ExceptionController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionController.class);

    @PostMapping("/test")
    public JsonResult test(@RequestParam("name") String name, @RequestParam("pass") String pass) {
        LOGGER.info("name: {}", name);
        LOGGER.info("pass: {}", pass);
        return new JsonResult();
    }

    @GetMapping("/business")
    public JsonResult testException() {
        try {
            int i = 1 / 0;
        } catch (Exception e) {
            ExceptionCast.cast(CommonCode.UNEXCEPTION_EXCEPTION);
        }
        return new JsonResult();
    }


    @GetMapping("/business2")
    public JsonResult testException2() {
        if (1 != 3) {
            // return new JsonResult(CommonCode.UNEXCEPTION_EXCEPTION);
            ExceptionCast.cast(CommonCode.UNEXCEPTION_EXCEPTION);
        }
        return new JsonResult(CommonCode.SUCCESS);
    }

    @GetMapping("/business3")
    public ResponseResult testException3() {
        if (1 != 3) {
            // return new JsonResult(CommonCode.UNEXCEPTION_EXCEPTION);
            ExceptionCast.cast(CommonCode.SERVICE_TIME_OUT);
        }
        return new ResponseResult(CommonCode.SUCCESS);
    }


}
